<?php

/**
 * uniBoard Debug Block
 *
 * Light and fast forum solution for web 2.0-like communities.
 *
 * @package		uniBoard
 * @author		Rafał Pitoń
 * @license		http://www.gnu.org/licenses/gpl-3.0.html
 * @since		Version 0.1
 * 
 * ------------------------------------------------------------------------
 * 
 * $Date: 2010-09-20 21:23:27 +0000 (Mon, 20 Sep 2010) $
 * $Revision: 64 $
 * $Author: rafio.xudb@gmail.com $
 */

// ------------------------------------------------------------------------

class action_debug{
	
	/**
	 * Main class pointer
	 *
	 * @var object
	 */
	
	private $appCore		= NULL;
	
	// ------------------------------------------------------------------------

	/**
	 * Initialise Action
	 *
	 * @param object $appCore
	 */
	
	function __construct( $appCore){
		
		// Store appCore pointer
		$this -> appCore = $appCore;

	}
	
	// ------------------------------------------------------------------------

	/**
	 * Draws Debugger
	 *
	 * @return string
	 */
	
	function draw(){
		
		// Create Template
		$tpl = new tpl_debug_raport( $this -> appCore);
		
		// Template Vars
		$tpl_vars = array(
			'session' 			=> '',
			'acl'			=> '',
			'db_queries' 	=> ''
		);
		
		// Draw User Data
		foreach ( $this -> appCore -> user as $item => $value)
		{
			$tpl_vars['session'] .= $tpl -> tpl_list_item( array( 'item_title' => htmlspecialchars( $item), 'item_value' => htmlspecialchars( var_export( $value, true))));
		}
		
		// Draw ACL Data
		foreach ( $this -> appCore -> user_acl as $item => $value)
		{
			$tpl_vars['acl'] .= $tpl -> tpl_list_item( array( 'item_title' => htmlspecialchars( $item), 'item_value' => htmlspecialchars( var_export( $value, true))));
		}
		
		// Draw Queries?
		if ( !empty( $this -> appCore -> db_queries_l))
		{
			// Iterate queries
			for ( $i = 0; $i <  $this -> appCore -> db_queries; $i ++)
			{
				$tpl_vars['db_queries'] .= $tpl -> tpl_query( array( 'query_content' => nl2br(htmlspecialchars( $this -> appCore -> db_queries_l[$i]))));
			}
		}
		
		// Return Complete Template
		return $tpl -> tpl_debug_body( $tpl_vars);
		
	}
	
}